local fuying = fk.CreateSkill {
  name = "lingling__fuying",
}

Fk:loadTranslationTable {
  ["lingling__fuying"] = "斧影",
  [":lingling__fuying"] = "你可以将两张黑桃牌当【杀】使用，此【杀】附带【贯石斧】和【祭祀斧】的效果，且目标选择弃置一张牌或令你摸一张牌。",

  ["#lingling__fuying"] = "斧影：你可以将两张黑桃牌当【杀】使用",
  ["#lingling__fuying-ask"] = "斧影：请弃置一张牌，或点取消令 %dest 摸一张牌",
}

fuying:addEffect("viewas", {
  pattern = "slash",
  prompt = "#lingling__fuying",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected < 2 and Fk:getCardById(to_select).suit == Card.Spade
  end,
  view_as = function(self, player, cards)
    if #cards ~= 2 then return end
    local card = Fk:cloneCard("slash")
    card.skillName = fuying.name
    card:addSubcards(cards)
    return card
  end,
})

fuying:addEffect(fk.TargetSpecified, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(fuying.name) and
        data.card and data.card.trueName == "slash" and not data.to.dead
        and table.contains(data.card.skillNames, fuying.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askToDiscard(data.to, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = fuying.name,
          cancelable = true,
          prompt = "#lingling__fuying-ask::" .. player.id,
        }) == 0 then
      player:drawCards(1, fuying.name)
    end
  end
})

fuying:addEffect(fk.CardEffectCancelledOut, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fuying.name) and data.from == player and data.card.trueName == "slash" and not data.to.dead
        and table.contains(data.card.skillNames, fuying.name) and not table.find(data.to:getCardIds("e"), function(c)
          return Fk:getCardById(c).name == "ling__axe"
        end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, id in ipairs(player:getCardIds("he")) do
      if not player:prohibitDiscard(id) and
          not (table.contains(player:getEquipments(Card.SubtypeWeapon), id) and Fk:getCardById(id).name == "ling__axe") then
        table.insert(cards, id)
      end
    end
    cards = room:askToDiscard(player, {
      min_num = 2,
      max_num = 2,
      include_equip = true,
      skill_name = "#ling__axe",
      cancelable = true,
      pattern = tostring(Exppattern { id = cards }),
      prompt = "#ling__axe-invoke::" .. data.to.id,
      skip = true,
    })
    if #cards > 0 then
      event:setCostData(self, { cards = cards })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(event:getCostData(self).cards, "#ling__axe", player, player)
    data.isCancellOut = false
  end,
})

fuying:addEffect(fk.Damage, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(fuying.name) and
        data.card and data.card.trueName == "slash" and data.by_user and
        player:isWounded() and table.contains(data.card.skillNames, fuying.name) and
        not table.find(data.to:getCardIds("e"), function(c)
          return Fk:getCardById(c).name == "ling__sacrifice_axe"
        end)
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = "#ling__sacrifice_axe",
    })
  end,
})

fuying:addAI(nil, "vs_skill")

return fuying
